package com.tieto.user.bean;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.imageio.ImageIO;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

@ManagedBean(name = "mediaBean")
@RequestScoped
public class MediaBean {
	private static final Logger LOG = LogManager.getLogger(MediaBean.class);

	public void paint(OutputStream out, Object data) throws IOException {
		LOG.debug("paint: " + data);
		String text = (String) data;
		if (text != null) {
			BufferedImage img = new BufferedImage(150, 50,
					BufferedImage.TYPE_INT_RGB);
			Graphics2D graphics2D = img.createGraphics();
			graphics2D.setBackground(new Color(190, 214, 248));
			graphics2D.setColor(new Color(0, 0, 0));
			graphics2D.clearRect(0, 0, 150, 50);
			graphics2D.setFont(new Font("Serif", Font.TRUETYPE_FONT, 12));
			graphics2D.drawString(text, 20, 25);
			ImageIO.write(img, "png", out);
		}
	}
}
